/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-149',
        defaultToolbar:[]
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.brandId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {


        //启用停用
        if (obj.event == "add") {
            if(!obj.config.data||obj.config.data.length==0){
                return false;
            }
            let selectData = obj.config.data.filter(e=>e.LAY_CHECKED);
            if(!selectData||selectData.length==0){
                return layer.alert("请选择至少1条数据！");
            }
            let categId = $("#categTwoId").val();
            selectData.forEach(e=>{
                e.categId=categId;
                e.status=2;
            })
            $.ajax({
                type: "POST",
                url: "/product/categorybrand/addEdit.action",
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(selectData),
                success: function (res) {
                    if (res.status == 200) {
                        layer.msg(res.message,{time: 1000},()=>{
                            zmnLayUtil.closeThisIframe(parent);
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message, {icon: 5, shift: 6});
                    }
                    return false;
                }
            });

        }
        return false;

    });

    //对外暴露的接口
    exports('plat_categorybrand_brand_list', {});
});

